<?php

require_once './library/Zend/Db/Table/Abstract.php';

class TableMap extends Zend_Db_Table_Abstract
{

    protected $_name;
    protected $_primary;
    protected $_db;
    protected $_registery;
    private $_select;
    protected $_assName;

    protected function _setup()
    {
        $this->_name = 'map';
        $this->_primary = 'IdMap';
        $this->_assName = 'ass_mapcompo';
        $this->_registry = Zend_Registry::getInstance();
        $this->_db = $this->_registry->get('adapter');
        parent::_setup();
    }

    public function getMapID($nMap)
    {
        $this->_select = $this->_db->select();
        $this->_select->from($this->_name, "IdMap");
        $this->_select->where('LblConfiguration = ?', $nMap);
        $this->_select = $this->_db->query($this->_select);
        $result = $this->_select->fetchAll();
        if (isset($result[0]))
            return $result;
        return false;
    }

    public function getMap($pIpMap)
    {
        $this->_select = $this->_db->select();
        $this->_select->from($this->_name, "ConfigurationXml");
        $this->_select->where('IdMap = ?', $pIpMap);
        $this->_select = $this->_db->query($this->_select);
        $result = $this->_select->fetchAll();
        if (isset($result[0]))
            return $result;
        return false;
    }

    public function getLstMap()
    {
        $this->_select = $this->_db->select();
        $this->_select->from($this->_name, array("IdMap", "Version", "LblConfiguration"));
        $this->_select = $this->_db->query($this->_select);
        $result = $this->_select->fetchAll();
        return $result;
    }

    public function addMap($pLblConfiguration, $pConfigurationXml)
    {
        $val = array('Version' => 'v_' . Date('ymdhis'),
            'LblConfiguration' => $pLblConfiguration,
            'ConfigurationXml' => $pConfigurationXml);
        $test = $this->_db->insert($this->_name, $val);
        return true;
    }

    public function deleteMap($pIdMap)
    {
        $this->delete($this->_db->quoteInto('LblConfiguration = ?', $pIdMap));
    }

}
?>